package cn.innosmart.aq.util;

import java.util.ArrayList;
import java.util.HashMap;

import cn.innosmart.aq.BuildConfig;
import cn.innosmart.aq.bean.AquariumBean;
import cn.innosmart.aq.bean.BoxBean;
import cn.innosmart.aq.bean.DeviceBean;
import cn.innosmart.aq.bean.Employee;
import cn.innosmart.aq.bean.RuleBean;
import cn.innosmart.aq.camera.models.CameraBean;

/**
 * Created by David on 2015/7/10.
 */
public class SystemConstant {
    // APP 端订阅的所有 Event 事件编号
    public static final int EVENT_ID_GATEWAY_UNKNOWN = -1;
    public static final int EVENT_ID_GATEWAY_MODECHANGED = 1;
    public static final int EVENT_ID_GATEWAY_DEVICEINCLUDED = 2;
    public static final int EVENT_ID_GATEWAY_DEVICEEXCLUDED = 3;
    public static final int EVENT_ID_CHANNEL_BASICVALUEUPDATED = 4;
    public static final int EVENT_ID_CHANNEL_SENSORVALUEUPDATED = 5;
    public static final int EVENT_ID_DEVICE_UPDATED = 6;
    public static final int EVENT_ID_DEVICE_UPGRADE_DOWNLOAD_PERCENTAGE = 7;
    public static final int EVENT_ID_DEVICE_UPGRADE_MD5 = 8;
    public static final int EVENT_ID_DEVICE_UPGRADE_UPGRADING = 9;
    public static final int EVENT_ID_DEVICE_UPGRADE_REBOOT = 10;
    // APP 端订阅的所有 Event 事件 topic
    public static final String EVENT_TOPIC_GATEWAY_MODECHANGED = "event/gateway.modeChanged";
    public static final String EVENT_TOPIC_GATEWAY_DEVICEINCLUDED = "event/gateway.deviceIncluded";
    public static final String EVENT_TOPIC_GATEWAY_DEVICEEXCLUDED = "event/gateway.deviceExcluded";
    public static final String EVENT_TOPIC_CHANNEL_BASICVALUEUPDATED = "event/channel.basicvalueUpdated";
    public static final String EVENT_TOPIC_CHANNEL_SENSORVALUEUPDATED = "event/channel.sensorvalueUpdated";
    public static final String EVENT_TOPIC_DEVICE_UPDATED = "event/DeviceManager.deviceUpdated";
    public static final String EVENT_TOPIC_UPGRADE_DOWNLOAD_PERCENTAGE = "event/SystemManager.FirmwareDownloadPercentage";
    public static final String EVENT_TOPIC_UPGRADE_MD5 = "event/SystemManager.FirmwareMD5";
    public static final String EVENT_TOPIC_UPGRADE_UPGRADING = "event/SystemManager.FirmwareUpgrading";
    public static final String EVENT_TOPIC_UPGRADE_REBOOT = "event/SystemManager.Reboot";
    // APP 端发出的所有 Event 事件 topic
    public static final String EVENT_TOPIC_APP_CONNECTION_SUCCESS = "event/connection.connected";
    //头像
    public static final String HEAD_ICON = "headicon";
    //SharedPrefrence
    public static final String Count = "CountInfo";
    public static final String Project = "AQProject";
    //login status 0 未登录， 1登录成功
    public static final int Online = 1;
    public static final int Offline = 0;
    //版本模式 区分 个人版 1 企业版 2
//    public static final int PERSONALMODE = 1;
//    public static final int COMPANYMODE = 2;
    //版本模式 区分 简体版 1 繁体版 2
    public static final int MODE_CH = 1;
    public static final int MODE_TW = 2;
    public static String username = null;
    public static String nickname = "nick_name";
    public static String openid = ""; //wx

    public static String session_token = null;
    public static int loginStatus = 0;
    public static String server_uid = null;
    public static String login_url = "https://api.innosmart.cn/api/user/login";
    public static String modifyNickName_url = "https://api.innosmart.cn/api/user/change_nickname";
    public static String modifyPassword_url = "https://api.innosmart.cn/api/user/change_password";
    public static String updateLocation_url = "https://api.innosmart.cn/api/user/update_location";
    public static String addFriend_url = "https://api.innosmart.cn/api/user/add_friend";
    public static String removeFriend_url = "https://api.innosmart.cn/api/user/remove_friend";
    public static String getFriend_url = "https://api.innosmart.cn/api/user/get_friends";
    public static String nearByPeople_url = "https://api.innosmart.cn/api/user/people_nearby";
    public static String regist_url = "https://api.innosmart.cn/api/user/regist_lv1";
    public static String registverify_url = "https://api.innosmart.cn/api/user/send_verification_code";
//    public static String banner_url = "http://www.innosmart.cn/aq_app_info/Banner/banner.json";
    /**
     * Assign
     */
    public static String addEmployeeUrl = "https://api.innosmart.cn/api/device/addAssign"; //0 成功 1 账户不存在 2添加失败 3账户已被添加
    public static String removeEmployeeUrl = "https://api.innosmart.cn/api/device/removeAssign";
//    public static String getUserAssignUrl = "https://api.innosmart.cn/api/user/get_user_assign";
    public static String getUserAssignUrl = "https://api.innosmart.cn/api/device/getDeviceAssignTo";
    public static String assignToUrl = "https://api.innosmart.cn/api/device/assignTo";
    public static String updateAssignToUrl = "https://api.innosmart.cn/api/device/update_assignTo";
    public static String addBox_url = "https://api.innosmart.cn/api/device/add_device_with_fee";
    public static String modifyBox_url = "https://api.innosmart.cn/api/device/update_device";
    public static String removeBox_url = "https://api.innosmart.cn/api/device/remove_device";
    public static String getChartUrl="https://api.innosmart.cn/api/device/get_chart_data";
    public static String other_history_url = "http://tsd.innosmart.cn:4242/api/query?start=%1$s-ago&m=sum:%2$s-avg:cn.innosmart.tsdb.svalue%%7Bid=%3$s,did=%4$s%%7D";
    public static String switch_history_url = "http://tsd.innosmart.cn:4242/api/query?start=%1$s&end=%2$s&m=sum:cn.innosmart.tsdb.svalue%%7Bid=%3$s,did=%4$s%%7D";
    public static String water_lever_history_url = "http://tsd.innosmart.cn:4242/api/query?start=%1$s&end=%2$s&m=sum:cn.innosmart.tsdb.svalue%%7Bid=%3$s,did=%4$s%%7D";
    public static String feeder_history_url = "http://tsd.innosmart.cn:4242/api/query?start=%1$s&end=%2$s&m=sum:cn.innosmart.tsdb.svalue%%7Bid=%3$s,did=%4$s%%7D";
    public static String add_work_log_temp = "https://api.innosmart.cn/LogTableMeta/create";
    public static String delete_work_log_temp = "https://api.innosmart.cn/LogTableMeta/destroy";
    public static String add_work_log = "https://api.innosmart.cn/LogTableData/create";
    public static String get_worklog_url = "https://api.innosmart.cn/LogTableData/find?where={\"template\":\"%1$s\"}&limit=0";
    public static String get_worklog_temp_url = "https://api.innosmart.cn/LogTableMeta/find?where={\"creator\":\"%1$s\"}";
    public static String findPasswird_verify = "https://api.innosmart.cn/api/user/send_reset_password_code";
    public static String resetPassword_url = "https://api.innosmart.cn/api/user/reset_password";
    public static String getNewOrderID_url = "https://api.innosmart.cn/api/order/order_id";

    public static ArrayList<BoxBean> boxBeanList = null;
    public static ArrayList<AquariumBean> aquariumList = null;
    public static HashMap<String, DeviceBean> deviceBeanHashMap = null;
    public static HashMap<String, CameraBean> cameraBeanHashMap = null;
    public static ArrayList<RuleBean> conditionRuleList = null;
    public static ArrayList<Object> ruleList = new ArrayList<>();
    public static ArrayList<Object> sceneList = null;
    public static ArrayList<Object> scheduleList = null;
    public static ArrayList<Employee> employees=null;
    public static AquariumBean currentAquariumBean = null;
    public static boolean isIncluding = false;
    public static int excludedCount = 0;
    public static int includingDeviceNum = 0;
    public static boolean isExcluding = false;
    public static boolean isRemoveFailedNode = false;
    public static boolean isRunning = false;
    public static int MODE = BuildConfig.MODE;
    public static int LOCAL_MODE = BuildConfig.LOCAL_MODE;
    public static BoxBean currentBoxBean;

    public static int has_check_fw_version_in_current_fragment = 0;

    public static int heart_enable = 0;
    public static int heart_pns_priority = 0; //4 normal, 5 important, 6 very important

    /**
     * 根据EventName生成EventType
     * @param eventName
     * @return
     */
    public static int getEventType(String eventName) {
        int eventType = -1;
        if (null == eventName)
            return eventType;
        if (eventName.contains(SystemConstant.EVENT_TOPIC_GATEWAY_MODECHANGED))
            eventType = SystemConstant.EVENT_ID_GATEWAY_MODECHANGED;
        else if (eventName.contains(SystemConstant.EVENT_TOPIC_GATEWAY_DEVICEINCLUDED))
            eventType = SystemConstant.EVENT_ID_GATEWAY_DEVICEINCLUDED;
        else if (eventName.contains(SystemConstant.EVENT_TOPIC_GATEWAY_DEVICEEXCLUDED))
            eventType = SystemConstant.EVENT_ID_GATEWAY_DEVICEEXCLUDED;
        else if (eventName.contains(SystemConstant.EVENT_TOPIC_CHANNEL_BASICVALUEUPDATED))
            eventType = SystemConstant.EVENT_ID_CHANNEL_BASICVALUEUPDATED;
        else if (eventName.contains(SystemConstant.EVENT_TOPIC_CHANNEL_SENSORVALUEUPDATED))
            eventType = SystemConstant.EVENT_ID_CHANNEL_SENSORVALUEUPDATED;
        else if (eventName.contains(SystemConstant.EVENT_TOPIC_DEVICE_UPDATED))
            eventType = SystemConstant.EVENT_ID_DEVICE_UPDATED;
        else if (eventName.contains(SystemConstant.EVENT_TOPIC_UPGRADE_DOWNLOAD_PERCENTAGE))
            eventType = SystemConstant.EVENT_ID_DEVICE_UPGRADE_DOWNLOAD_PERCENTAGE;
        else if (eventName.contains(SystemConstant.EVENT_TOPIC_UPGRADE_MD5))
            eventType = SystemConstant.EVENT_ID_DEVICE_UPGRADE_MD5;
        else if (eventName.contains(SystemConstant.EVENT_TOPIC_UPGRADE_UPGRADING))
            eventType = SystemConstant.EVENT_ID_DEVICE_UPGRADE_UPGRADING;
        else if (eventName.contains(SystemConstant.EVENT_TOPIC_UPGRADE_REBOOT))
            eventType = SystemConstant.EVENT_ID_DEVICE_UPGRADE_REBOOT;
        else
            eventType = SystemConstant.EVENT_ID_GATEWAY_UNKNOWN;
        return eventType;
    }

    /**
     * 根据eventType生成EventName
     * @param eventType
     * @return
     */
    public static String getEventName(int eventType) {
        String eventName = null;
        switch (eventType) {
            case SystemConstant.EVENT_ID_GATEWAY_MODECHANGED:
                eventName = SystemConstant.EVENT_TOPIC_GATEWAY_MODECHANGED;
                break;
            case SystemConstant.EVENT_ID_GATEWAY_DEVICEINCLUDED:
                eventName = SystemConstant.EVENT_TOPIC_GATEWAY_DEVICEINCLUDED;
                break;
            case SystemConstant.EVENT_ID_GATEWAY_DEVICEEXCLUDED:
                eventName = SystemConstant.EVENT_TOPIC_GATEWAY_DEVICEEXCLUDED;
                break;
            case SystemConstant.EVENT_ID_CHANNEL_BASICVALUEUPDATED:
                eventName = SystemConstant.EVENT_TOPIC_CHANNEL_BASICVALUEUPDATED;
                break;
            case SystemConstant.EVENT_ID_CHANNEL_SENSORVALUEUPDATED:
                eventName = SystemConstant.EVENT_TOPIC_CHANNEL_SENSORVALUEUPDATED;
                break;
            case SystemConstant.EVENT_ID_DEVICE_UPDATED:
                eventName = SystemConstant.EVENT_TOPIC_DEVICE_UPDATED;
                break;
            case SystemConstant.EVENT_ID_DEVICE_UPGRADE_DOWNLOAD_PERCENTAGE:
                eventName = SystemConstant.EVENT_TOPIC_UPGRADE_DOWNLOAD_PERCENTAGE;
                break;
            case SystemConstant.EVENT_ID_DEVICE_UPGRADE_MD5:
                eventName = SystemConstant.EVENT_TOPIC_UPGRADE_MD5;
                break;
            case SystemConstant.EVENT_ID_DEVICE_UPGRADE_UPGRADING:
                eventName = SystemConstant.EVENT_TOPIC_UPGRADE_UPGRADING;
                break;
            case SystemConstant.EVENT_ID_DEVICE_UPGRADE_REBOOT:
                eventName = SystemConstant.EVENT_TOPIC_UPGRADE_REBOOT;
                break;
            default:
                eventName = "";
                break;
        }
        eventName = eventName.replace("event/", "");
        return eventName;
    }

}
